﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class FriendsBlackList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.AddNewMatchSentence_PageTitle;
            // security part
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");

            OnlineUser ou = (OnlineUser)Session["User"];

            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");
            //removed - this page will be visible to all the users. Not only to premium users.
            //if (!ou.IsPremium)
            //    Response.Redirect("~/GeneralMessage.aspx?MessageString=gfkkjFSDei3w7lzTD");

            if (!IsPostBack)
            {
                this.FriendsBlacklistDataSourse.SelectParameters.Add("UserId", ou.UserId);
                this.DeclinedFriendsDataSourse.SelectParameters.Add("UserId", ou.UserId);
            }
            this.BlacklistedUsersLabel.Visible = (BlacklistGridView.Rows.Count > 0);
            this.DeclinedUsersTitleLabel.Visible = (RecentlyDeclinedGridview.Rows.Count > 0);
        }

        protected void DeleteBlacklistEntry(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
                OnlineUser ou = (OnlineUser)Session["User"];
                string Answer = GND.ReadNivdalStringData("SuggestionId", "Language", "Nivdal_FriendshipStopBeingFriends", e.CommandArgument, ou.Language);
                Response.Redirect("~/FriendsBlackList.aspx?Message=" + Answer);
            }
        }

        protected void DeleteRejectedEntry(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
                OnlineUser ou = (OnlineUser)Session["User"];
                string Answer = GND.ReadNivdalStringData("SuggestionId", "Language", "Nivdal_FriendshipStopBeingFriends", e.CommandArgument, ou.Language);
                Response.Redirect("~/FriendsBlackList.aspx?Message=" + Answer);
            }
        }


        protected string DelteBlacklistOnClientClick()
        {
            return ("return confirm('" + Resources.Resource.FriendsBlackList_DeleteBlackListQuestion + "')");
        }

        protected string DelteDeclineOnClientClick()
        {
            return ("return confirm('" + Resources.Resource.FriendsBlackList_DeleteDeclineQuestion + "')");
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}